package com.flashcash.solu.common.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import com.flashcash.solu.R;
import com.flashcash.solu.bean.SkypayBanksAddressBean;

import java.util.List;

public class BankProvinceAdapter extends BaseAdapter {
    private final List<SkypayBanksAddressBean> mDatas;
    private final Context mContext;
    private final BankProvinceAdapter.OnWithdrawChannelClickListener mOnItmeClickListener;

    public BankProvinceAdapter(List<SkypayBanksAddressBean> datas, Context context, BankProvinceAdapter.OnWithdrawChannelClickListener
            listener) {
        mDatas = datas;
        mContext = context;
        mOnItmeClickListener = listener;
    }


    @Override
    public int getCount() {
        return mDatas != null ? mDatas.size() : 0;
    }

    @Override
    public SkypayBanksAddressBean getItem(int position) {
        return mDatas.get(position);
    }

    @Override
    public long getItemId(int position) {
        return 0;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        if (convertView == null) {
            convertView = LayoutInflater.from(mContext).inflate(R.layout.item_dialog_withdraw_channel_list,
                    parent, false);
        }
        final SkypayBanksAddressBean data = getItem(position);

        ((TextView) convertView.findViewById(R.id.text_view_withdraw_channel)).setText(data
                .getName());

        convertView.setOnClickListener(v -> mOnItmeClickListener.onItemClick(data));
        return convertView;
    }

    public void dataChanged(List<SkypayBanksAddressBean> withdrawChannels) {
        this.mDatas.clear();
        this.mDatas.addAll(withdrawChannels);

        this.notifyDataSetChanged();
    }

    public interface OnWithdrawChannelClickListener {
        void onItemClick(SkypayBanksAddressBean data);
    }
}
